package dao.impl;

import dao.SellListDao;
import entity.Commodity;
import entity.SellList;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import utils.DruidUtils;

import java.util.List;

public class SellListDaoImpl implements SellListDao {
    private JdbcTemplate jdbcTemplate = new JdbcTemplate(DruidUtils.getDataSource());

    @Override
    public List<SellList> selectSellLists() {
        String sql = "select * from commodity_client";
        List<SellList> query = jdbcTemplate.query(sql, new BeanPropertyRowMapper<>(SellList.class));
        return query;
    }

    @Override
    public void insertSellList(Commodity commodity,SellList sellList) {
        String sql = "insert into commodity_client values(?,?,null,?,?,?,null)";
        jdbcTemplate.update(sql,sellList.getCid(),sellList.getClid(),sellList.getSid(),sellList.getCount(),commodity.getSalesPrice());
    }
}
